//客户端引入mqtt
let mqtt = require('mqtt');
 
let client = mqtt.connect('mqtt://localhost', {
 port: 5112,
 clientId: 'cli_pub',
})
 
let num = 0;
setInterval(function (){
 client.publish('test', 
 'Hello mqtt ' + (++num),
 {qos:1},
 () => console.log(num));
}, 1000)